﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Biblio.Domain;
using Biblio.DataAccess;

namespace BiblioWeb.Controllers
{
    public class HomeController : Controller
    {
        private BiblioDbContext db;
        private MaterialRepo repoMaterial;

        public HomeController()
        {
            db = new BiblioDbContext();
            repoMaterial = new MaterialRepo(db);
        }

        public ActionResult Index()
        {
            ViewBag.Message = "BiblioWeb 2013";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Usted puede reservar sus libros favoritos, rápido y fácil desde casa.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Contacto.";

            return View();
        }

        public ActionResult Buscar(string busqueda)
        {
            IList<Material> materiales = new List<Material>();
             if(!String.IsNullOrEmpty(busqueda))
                 materiales = repoMaterial.BuscarPorTitulo(busqueda);
           
            ViewBag.Message = "Buscar.";

            return View(materiales);
        }
    }
}
